var path = "../";

var lineList = [];
var barList = [];
var date = [];
var myChart = echarts.init(document.getElementById('divProgress'));
$.ajax({
    type: "post",
    async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
    url: path + "customer/getCustomerFlow",    //请求发送到getTig处
    data: {day: 1},
    dataType: "json",        //返回数据形式为json
    success: function (result) {
        //请求成功时执行该函数内容，result即为服务器返回的json对象
        if (result) {
            if (result.lineList != undefined || result.barList != undefined) {
                for (var i = 0; i < result.barList.length; i++) {
                    barList.push(result.barList[i].tigBarNum);
                }
                for (var i = 0; i < result.lineList.length; i++) {
                    lineList.push(result.lineList[i].tigLineNum);
                }
            } else {
                alert("数据过多，稍等片刻");
            }
            myChart.hideLoading();
            var option = {
                title: {
                    text: '总客流量'
                },
                tooltip: {},
                legend: {
                    data: ['当天客流量', '昨天客流量']
                },
                xAxis: {
                    data: ["00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00",
                        "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00"]
                },
                dataZoom: [{
                    type: 'slider',
                    show: true,
                    xAxisIndex: [0],
                    left: '9%',
                    bottom: -5,
                    start: 10,
                    end: 90 //初始化滚动条
                }],
                yAxis: {},
                toolbox: {
                    show: true,
                    orient: 'horizontal',
                    showTitle: true,
                    feature: {
                        magicType: {
                            type: ['line', 'bar']
                        },
                        saveAsImage: {
                            type: 'png',
                            show: true,
                            title: '保存为图片',
                        },
                        restore: {show: true}
                    }
                },
                series: [
                    {
                        name: '当天客流量',
                        type: 'bar',
                        data: barList
                    }, {
                        name: '昨天客流量',
                        type: 'line',
                        data: lineList
                    }
                ]
            };
            myChart.setOption(option);
        }
    },
    error: function (errorMsg) {
        //请求失败时执行该函数
        alert("图表请求数据失败!");
        myChart.hideLoading();
    }
});

function reboot() {
    window.location.reload();
}
function toDayClick(day) {
    $.ajax({
        type: "post",
        async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
        url: path + "customer/getCustomerFlow",    //请求发送到getTig处
        data: {day: day},
        dataType: "json",        //返回数据形式为json
        success: function (result) {
            //请求成功时执行该函数内容，result即为服务器返回的json对象
            if (result) {
                lineList = [];
                date = [];
                if (result.lineList != undefined) {
                    for (var i = 0; i < result.lineList.length; i++) {
                            lineList.push(result.lineList[i].tigLineNum);
                    }
                }else{
                    alert("数据过多,请稍后重试！");
                    myChart.hideLoading();
                }
                if (day == 1) {
                    date = ["00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00",
                        "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00"];
                } else {
                    if (result.lineList != undefined) {
                    for (var i = 0; i < result.lineList.length; i++) {
                            date.push(result.lineList[i].tigHour);
                        }
                    }
                }
                var option = {
                    title: {
                        text: '总客流量'
                    },
                    tooltip: {},
                    legend: {
                        data: ['客流量']
                    },
                    xAxis: [
                        {
                            data: date
                        }
                    ],
                    dataZoom: [{
                        type: 'slider',
                        show: true,
                        xAxisIndex: [0],
                        left: '9%',
                        bottom: -5,
                        start: 10,
                        end: 90 //初始化滚动条
                    }],
                    yAxis: {},
                    toolbox: {
                        show: true,
                        orient: 'horizontal',
                        showTitle: true,
                        feature: {
                            magicType: {
                                type: ['line']
                            },
                            saveAsImage: {
                                type: 'png',
                                show: true,
                                title: '保存为图片',
                            },
                            restore: {show: true}
                        }
                    },
                    series: [
                        {
                            name: '总客流量',
                            type: 'line',
                            data: lineList
                        }
                    ]
                };
                myChart.clear();
                option.series[0].data = lineList;
                option.xAxis[0].data = date;
                myChart.setOption(option);
            }
        },
        error: function (errorMsg) {
            //请求失败时执行该函数
            alert("图表请求数据失败!");
            myChart.hideLoading();
        }
    });
}
